package net.wsfcp.android.http.mvp.presenter;

import net.wsfcp.android.base.BasePresenter;
import net.wsfcp.android.bean.resultbean.UserBean;
import net.wsfcp.android.bean.resultbean.PublicKeyBean;
import net.wsfcp.android.http.mvp.contract.MyContract;
import net.wsfcp.android.http.mvp.model.MyModel;
import net.wsfcp.android.http.mvp.IModel;
import net.wsfcp.android.ui.view.my.fragment.MyFragment;

import java.util.HashMap;


//我的页面  自动登陆/获取公钥
public class MyPresenter extends BasePresenter<MyFragment> implements
        MyContract.MyPresenter {

    @Override
    public void getPublicKey() {
        ((MyModel) getiModelMap().get("publickey")).getPublicKey(new MyModel.PublicKeyHint() {
            @Override
            public void getPublicKeySuccess(PublicKeyBean bean) {
                getIView().getPublicKeySuccess(bean);  //成功
            }

            @Override
            public void getPublicKeyFail(String str) {
                getIView().getPublicKeyFail(str);  //成功
            }

        });
    }

    @Override
    public void autoLogin(final String name, final String pwd) {
        ((MyModel) getiModelMap().get("autologin")).autoLogin(name, pwd, new MyModel.AutoLoginHint() {

            @Override
            public void autoLoginSuccess(UserBean bean) {
                getIView().autoLoginSuccess(bean);  //成功
            }

            @Override
            public void autoLoginFail(String str) {
                getIView().autoLoginFail(str);  //失败
            }

        });


    }

    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new MyModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> map = new HashMap<>();
        map.put("publickey", models[0]);
        map.put("autologin", models[0]);
        return map;
    }


}
